/*
mob_player_var.dm
All of the player overrides for the vars delcared in {mob_var.dm} can be found here
*/

mob/player
	hp    = 50
	maxhp = 50

	mp   =25
	maxmp=25

	str  =1
	vit  =1
	skill=1
	agi  =1
	int	 =1
	wis  =1
	luck =1

	atkspd=13

	class="Tyro"
	mobtype="Humanoid"

	level=1
	expgive=0

	respawn =""
	tx =0
	ty =0
	tz =0

	rundelay = 2

	mouse_opacity=2

	Move()
		. = ..()
		if(.)
			for(var/monster/m in range(13,src))
				if(m.sleeping)
					m.sleeping = 0
					spawn(rand(1,20))
						if(m)
							m.ai()

	proc
		change_class()
			update_skills()

		update_skills()
			var/count=2

			src << output("Skill", "skills.grid:1,1")
			src << output("Learned Level", "skills.grid:2,1")
			src << output("Description", "skills.grid:3,1")

			if(istext(classlvl[class])) classlvl[class] = text2num(classlvl[class])

			for(var/x=1 to classlvl[class])
				var/list/l = skills[class]
				if(l.len >= x)

					var/list/lvsk = l[x]

					if(lvsk)
						for(var/skill/s in lvsk)
							src << output(s, "skills.grid:1,[count]")
							src << output("Level [x]", "skills.grid:2,[count]")
							src << output(s.desc, "skills.grid:3,[count++]")

		update_contents()
			for(var/x=1 to contents.len)
				src << output(contents[x],"main.grid:1,[x]")
			src << output(null,"main.grid:1,[contents.len+1]")

		update_stats()
			var/list/stats = list("str"="Strength",
								  "vit"="Vitality","agi"="Agility","skill"="Skill","wis"="Wisdom","int"="Intelligence",
								  "luck"="Luck")
			var/list/other = list("name"="Name","class"="Class","jewels"="Jewels")+stats
			update_bars()
			for(var/x=1 to other.len)
				src << output(other[other[x]] ? other[other[x]] : other[x], "equipment.grid:1,[x+3]")
				if(other[x] in stats)
					src << output("[calc(other[x])] (+[(calc(other[x])-vars[other[x]])])", "equipment.grid:2,[x+3]")
				else
					if(other[x] == "class")
						src << output("[vars[other[x]]] ([classlvl[class]])", "equipment.grid:2,[x+3]")
					else
						src << output(vars[other[x]], "equipment.grid:2,[x+3]")

		update_exp()
			winset(src, "main.expbar", "value=[bar_safe(classexp[class], classmexp[class])]")
			src << output("EXP", "equipment.grid:1,3")
			src << output("[classexp[class]]/[classmexp[class]]", "equipment.grid:2,3")

		update_hp()
			winset(src, "main.hpbar", "value=[bar_safe(hp, maxhp)]")
			src << output("Health", "equipment.grid:1,1")
			src << output("[hp]/[maxhp]", "equipment.grid:2,1")

		update_mp()
			winset(src, "main.mpbar", "value=[bar_safe(mp, maxmp)]")
			src << output("Energy", "equipment.grid:1,2")
			src << output("[mp]/[maxmp]", "equipment.grid:2,2")

		update_bars()
			update_exp()
			update_hp()
			update_mp()

		update_eqscreen()
			update_stats()
			update_equipment()

		update_equipment()
			for(var/o in equipment)
				var/obj/gettable/equipment/e = equipment[o]
				if(e)
					winset(src, "equipment.[ckey(o)]","image=\ref[fcopy_rsc(icon(e.icon, e.icon_state,frame=1))]")
				else
					winset(src, "equipment.[ckey(o)]","image=\"\"")

		regen_loop()
			spawn while(src)
				sleep(300)
				mp += int
				if(mp > maxmp)
					mp = maxmp
				update_mp()

	verb
		loadskillscreen()
			update_skills()
			winshow_center(src,"skills")

		loadeqscreen()
			update_eqscreen()
			winshow_center(src,"equipment")

proc/bar_safe(min, max)
	if(istext(min)) min = text2num(min)
	if(istext(max)) max = text2num(max)
	if(!min)min=0
	if(!max)max=100
	. = round((min/max) * 100)
	if(.<0)		.=0
	if(.>100)	.=100